package com.joejag.mavenstats.server.reports.impls;

import com.joejag.mavenstats.client.dto.ReportDTO;
import com.joejag.mavenstats.server.dao.ProjectsDao;
import com.joejag.mavenstats.server.reports.CommonReportUtils;
import com.joejag.mavenstats.server.reports.Report;
import org.jfree.chart.JFreeChart;

import java.util.Map;

public class AllDependenciesReport implements Report
{
  private ProjectsDao projectsDao;

  public AllDependenciesReport(ProjectsDao projectsDao)
  {
    this.projectsDao = projectsDao;
  }

  public ReportDTO generateReport()
  {
    Map<String, Integer> result = CommonReportUtils.getOccurancesMapOfDependenciesByGrouping(projectsDao);

    String body = "<ul>";
    for (String grouping : result.keySet())
      body += "<li>" + grouping + " :: " + result.get(grouping) + "</li>";

    body += "</ul>";

    return new ReportDTO(getReportName(), body);
  }

  public String getReportName()
  {
    return "All Dependencies";
  }

  public JFreeChart getJFreeChart()
  {
    throw new UnsupportedOperationException("not applicable");
  }
}
